//
//  WatchViewController.m
//  SmartWatch
//
//  Created by janshky on 2022/11/18.
//

#import "WatchViewController.h"
#import "FindWatchViewController.h"
#import "NoticeViewController.h"
#import "WatchFaceViewController.h"
#import "MyNameCardViewController.h"
#import "MyPayCodeViewController.h"
#import "HandleBrightViewController.h"
#import "RemindViewController.h"
#import "ClockSetViewController.h"
#import "HealthViewController.h"
#import "SubmitLoadingView.h"

@interface WatchViewController ()
@property(nonatomic,strong) UIView *topBackContainer;
@property(nonatomic,strong) UILabel *unbindView;
@property(nonatomic,strong) UILabel *bindView;

@end

@implementation WatchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.statusBarDefault = NO;
    self.isHideNavigationBar = YES;
    
    
    FlexFrameView *view = [[FlexFrameView alloc]initWithFlex:@"WatchViewController" Frame:self.view.bounds Owner:self];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
        make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
        make.top.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
    }];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setGradientLayerForTopContainer) name:FLEXDIDLAYOUT object:nil];
}



// 查找手表
- (void)jumpToFindWatch {
    SubmitLoadingView *resultView = [[SubmitLoadingView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth - 120, 245)];
    resultView.text = @"正在查找手表...";
    WeakSelf
    [resultView setLoadComplateBlock:^{
        [weakSelf.zh_popupController dismiss];
        
    }];
    self.zh_popupController = [zhPopupController new];
    self.zh_popupController.layoutType = zhPopupLayoutTypeCenter;
    self.zh_popupController.allowPan = NO;
    self.zh_popupController.maskAlpha = 0.7;
    self.zh_popupController.dismissOnMaskTouched = YES;
    [self.zh_popupController presentContentView:resultView];
}
// 消息通知
- (void)noticeClick {
    
    [self.navigationController pushViewController:[NoticeViewController new] animated:YES];
}

// 表盘管理
- (void)watchFaceClick {
    
    [self.navigationController pushViewController:[WatchFaceViewController new] animated:YES];
}

// 我的名片
- (void)MyNameCardClick {
    [self.navigationController pushViewController:[MyNameCardViewController new] animated:YES];
    
}

// 我的收款码
- (void)MyPayCodeClick {
    [self.navigationController pushViewController:[MyPayCodeViewController new] animated:YES];
}

// 抬手亮屏
- (void)HandleBrightClick {
    [self.navigationController pushViewController:[HandleBrightViewController new] animated:YES];
}

// 久坐提醒
- (void)remindClick {
    [self.navigationController pushViewController:[RemindViewController new] animated:YES];
}

// 闹钟设置
- (void)clockClick {
    [self.navigationController pushViewController:[ClockSetViewController new] animated:YES];
}

// 女性健康
- (void)healthClick {
    [self.navigationController pushViewController:[HealthViewController new] animated:YES];
}



// 解绑设备
- (void)unbindClick {
    QMUIAlertController *alertC = [[QMUIAlertController alloc]initWithTitle:@"是否解绑设备？" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet];
    QMUIAlertAction *unbind = [QMUIAlertAction actionWithTitle:@"解绑设备" style:QMUIAlertActionStyleDestructive handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
        
    }];
    
    [alertC addAction:unbind];
    [alertC addCancelAction];
    [alertC showWithAnimated:YES];
    
}

-(void)addDevice {
    
    FindWatchViewController *vc = FindWatchViewController.new;
    [self showViewController:vc sender:self];
//    self.unbindView.hidden = YES;
//    self.bindView.hidden = NO;
}


- (void)FlexSet {
    [[NSNotificationCenter defaultCenter]postNotificationName:@"jumpFlexSet" object:nil];
}

- (void)setGradientLayerForTopContainer {
    
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = self.topBackContainer.bounds;
    gl.startPoint = CGPointMake(0.5, 0);
    gl.endPoint = CGPointMake(0.5, 1);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:88/255.0 green:189/255.0 blue:179/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    UIGraphicsBeginImageContext(self.topBackContainer.size);
    [gl renderInContext:UIGraphicsGetCurrentContext()];
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.topBackContainer.backgroundColor = [UIColor colorWithPatternImage:image];
}

@end
